package fr.teuteuf.runstickmanrun.map.block;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.physics.box2d.World;

import fr.teuteuf.runstickmanrun.map.MapGenerator;
import fr.teuteuf.runstickmanrun.map.tile.DamagingSolidBoxTile;
import fr.teuteuf.runstickmanrun.map.tile.SolidBoxTile;
import fr.teuteuf.runstickmanrun.map.tile.Tile;

public class PicksBlock extends AbstractMapBlock {

	public PicksBlock(int difficultyLevel) {
		setDifficulties(0, 2, 5);
		setCurrentLevel(difficultyLevel);
	}
	
	@Override
	public int generateBlock(World world, MapGenerator mg, int nbHorizontalTiles) {
	
		int holesNumber = MathUtils.random(1, 10);
		int holeSize;
		int blockLength = 0;
		int pickDamage = 5;
		
		if(getCurrentLevel() >= getMaxDifficultyLevel()) {
			holeSize = MathUtils.random(2, 10);
		} else {
			holeSize = MathUtils.random(2, 8);
		}
		
		for(int i = 0; i < (holeSize + 1) * holesNumber + 1; i++) {
			if(i % (holeSize + 1) == 0) {
				if(getCurrentLevel() < getMedDifficultyLevel()) {
					mg.addTile(new SolidBoxTile((byte) 11, 0, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 1 * Tile.TILE_SIZE, world));
					mg.addTile(new SolidBoxTile((byte) 11, 1, 2, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 0 * Tile.TILE_SIZE, world));
					blockLength++;
					mg.addTile(new SolidBoxTile((byte) 11, 2, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 1 * Tile.TILE_SIZE, world));
					mg.addTile(new SolidBoxTile((byte) 11, 1, 2, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 0 * Tile.TILE_SIZE, world));
				} else {
					mg.addTile(new SolidBoxTile((byte) 11, 7, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 1 * Tile.TILE_SIZE, world));
					mg.addTile(new SolidBoxTile((byte) 11, 1, 2, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 0 * Tile.TILE_SIZE, world));
				}
			} else {
				mg.addTile(new DamagingSolidBoxTile((byte) 4, 3, 8, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 1 * Tile.TILE_SIZE, world, pickDamage));
				mg.addTile(new Tile(1, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, 0 * Tile.TILE_SIZE));
			}
			blockLength++;
		}
		
		return nbHorizontalTiles + blockLength;
	}

}
